package aiku.numericalcontroloa.Controller.CompanyCulture;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Model.Dto.CompanyCulture.MaterialDto;
import aiku.numericalcontroloa.Model.Entity.CompanyCulture.Material;
import aiku.numericalcontroloa.Service.CompanyCulture.MaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 资料控制层
 * @Author 黄广庭
 * @Date 2024/1/8 14:41
 */

@RestController
@RequestMapping("/material")
@Slf4j
public class MaterialCont {
    private final MaterialService materialService;

    public MaterialCont(MaterialService materialService) {
        this.materialService = materialService;
    }

    /**
     * 添加资料
     * @param material 资料对象
     * @return 结果
     */
    @PostMapping("/addMaterial")
    public Result addMaterial(@RequestBody Material material){
        return materialService.addMaterial(material);
    }

    /**
     * 删除资料
     * @param material 资料对象
     * @return 结果
     */
    @PostMapping("/deleteMaterial")
    public Result deleteMaterial(@RequestBody Material material){
        return materialService.deleteMaterial(material.getId());
    }

    /**
     * 获取资料详情
     * @param materialDto
     * @return
     */
    @PostMapping("/getMaterial")
    public Result getMaterial(@RequestBody MaterialDto materialDto){
        return materialService.getMaterial(materialDto);
    }

    /**
     * 获取全部资料和模糊查询
     * @param materialDto
     * @return
     */
    @PostMapping("/getMaterialList")
    public Result getMaterialList(@RequestBody MaterialDto materialDto){
        return materialService.getMaterialList(materialDto);
    }

    /**
     * 浏览量增加
     * @param material
     * @return
     */
    @PostMapping("/addViewCount")
    public Result addViewCount(@RequestBody Material material){
        return materialService.addViewCount(material);
    }
}
